package com.info.zhiduoduo.repository.mapper.system;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.info.zhiduoduo.repository.dto.system.InvoiceCategoryDto;
import com.info.zhiduoduo.repository.dto.system.InvoiceCategoryOneDto;
import com.info.zhiduoduo.repository.entity.system.InvoiceCategory;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface InvoiceCategoryMapper extends BaseMapper<InvoiceCategory> {

    // 查询 一级分类列表
    @Select(" select i.* , c.company_name as compname from zdd_system_invoicecategory i LEFT JOIN zdd_crowdsource_company_party c ON i.compid = c.id " +
            " where 1 = 1 and i.parentid = 0 and deleted = 0 " +
            " ${whereStr}  order by i.createtime desc  ")
    List<InvoiceCategoryOneDto> queryInvoiceCategoryOneList(@Param("whereStr") String whereStr);


    // 查询 一级列表
    @Select(" select * from  zdd_system_invoicecategory  where parentid = 0 and deleted = 0 " +
            " AND IF( ISNULL(#{partyId}) , 1=1 , compid = #{partyId}  ) " +
            " AND IFNULL(name,'') like '%${categoryName}%' " +
            " order by compid desc ")
    List<InvoiceCategoryDto> selectInvoiceCategoryList(@Param("partyId") Integer partyId, @Param("categoryName") String categoryName);

    // 查询 二级列表
    @Select(" select * from  zdd_system_invoicecategory  where parentid = #{parentid} and deleted = 0 ")
    List<InvoiceCategoryDto> selectInvoiceCategoryByTwoList(int parentid);
}
